package ysq.xyg.${module}.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.${module}.model.po.${entity};
import ysq.xyg.${module}.model.vo.${entity}Vo;
import ysq.xyg.${module}.service.${entity}Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * ${tableComment}controller层
 *
 * @author ${author}
 * @date ${.now}
 */
@RestController
public class ${entity}Controller extends BaseController {

    private static Logger log= LoggerFactory.getLogger(${entity}Controller.class);
    @Resource
    private ${entity}Service ${entity?uncap_first}Service;

    private ${entity} ${entity?uncap_first};

    /**
     * 分页查询
     *
     * @param ${entity?uncap_first}Vo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}",className = "${classLogName}",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/${entity?uncap_first}/page",method = RequestMethod.POST)
    public ReturnEntity page(${entity}Vo ${entity?uncap_first}Vo, int pageSize, int pageNum){
        ReturnEntity returnEntity = ${entity?uncap_first}Service.page(${entity?uncap_first}Vo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author ${author}
     * @date ${.now}
     */
    @RequestMapping(value = "/${entity?uncap_first}/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/${module}/${entity?uncap_first}UpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            ${entity?uncap_first} = ${entity?uncap_first}Service.selectByPrimaryKey(id);
            view.addObject("${entity?uncap_first}", ${entity?uncap_first});
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}",className = "${classLogName}",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/${entity?uncap_first}/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return ${entity?uncap_first}Service.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param ${entity?uncap_first}Vo Vo对象
     * @author ${author}
     * @date ${.now}
     */
    @BaseLog(module = "${moduleLogName}",className = "${classLogName}",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/${entity?uncap_first}/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,${entity}Vo ${entity?uncap_first}Vo){
        return ${entity?uncap_first}Service.addOrUpdate(${entity?uncap_first}Vo,acceptCurrentUser(request));
    }
}